home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1998
/
MacHack 1998.toast
/
Sessions
/
STL
/
Slides
/
STL9.cp
< prev
Wrap
Text File
|
1998-06-18
|
841b
|
31 lines
// STL9.cp
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "Standard strings are easy to initialize.";
a += " And they can grow without end as needed.";
string::iterator iter = find(a.begin(), a.end(), 'A');
if (iter != a.end())
{
size_t offset = iter - a.begin();
a[offset] = 'a'; // They use array notation like C strings.
}
iter = find(a.begin(), a.end(), '.');
if (iter != a.end())
{
a.erase(iter); // They are STL containers.
}
cout << a << endl;
cout << "Size is ";
// cout << strlen(a); // No coercion to char *.
cout << strlen(a.c_str()); // But it easy to get a char *.
cout << "." << endl;
// They automagically delete their allocated memory when they go out of scope.
}
// Standard strings are easy to initialize and they can grow without end as needed.
// Size is 80.